Skip to main content

Analyze the connection between electricity consumption and housing types

The script below can be used as a starting point for creating statistics and analyzes of the relationship between housing types and electricity consumption measured in January 2023 as well as the average for 2023. Electricity consumption data is obtained from electricity readings from electricity meters throughout the country on a monthly basis via the Elhub database. We look at factors such as housing type, housing size, year of construction, number of people and income, and create figures for both actual and relative electricity consumption per home. Relative consumption means consumption per m2 of usable area.

Note that the results generated by the script cannot be considered official statistics without further quality control and processing of the data.

 textblock
Analysis of correlation between power consumption, type of dwelling, dwelling size, year of construction, number of people and income
-------------------------------------------------------------------------------------------------------------------------------------
endblock

require no.ssb.fdb:34 as db

create-dataset elhubdata

for mnd, dag in 1:12, 31 28 31 30 31 30 31 31 30 31 30 31
  import db/ELHUB_PERS_STROMFORBRUK date_fmt(2023, $mnd, $dag) as powerconsumption++$mnd, outer_join
  import db/ELHUB_PERS_KRAFTPRODUKSJON date_fmt(2023, $mnd, $dag) as powerproduction++$mnd, outer_join
end

generate avgconsumption = rowmean(powerconsumption1, powerconsumption2, powerconsumption3, powerconsumption4, powerconsumption5, powerconsumption6, powerconsumption7, powerconsumption8, powerconsumption9, powerconsumption10, powerconsumption11, powerconsumption12)

keep powerconsumption1 avgconsumption

import db/ELHUB_PERS_MALEPUNKTID_FNR 2023-01-31 as personid
collapse(sum) powerconsumption1 avgconsumption, by(personid)

import db/BOFORHOLD_BYGNINGSTYPE 2023-01-01 as buildingtype
import db/BOFORHOLD_HUSHTYPE 2023-01-01 as householdtype
import db/BOFORHOLD_BRUKSENHETSTYPE 2023-01-01 as unittype

import db/BOFORHOLD_BYGGEAAR 2023-01-01 as constructionyear
import db/BOFORHOLD_ANTALL_ROM 2023-01-01 as num_rooms
import db/BOFORHOLD_BRUKSAREAL 2023-01-01 as usablearea

import db/BEFOLKNING_ANTPERS_I_REGSTAT_FAMNR 2023-01-01 as num_people
import db/INNTEKT_HUSH_IES 2022-12-31 as householdincome

generate consumption_per_m2 = powerconsumption1 / usablearea

summarize powerconsumption1 avgconsumption consumption_per_m2 constructionyear num_rooms usablearea num_people householdincome

tabulate householdtype
tabulate unittype
keep if householdtype == 'P' & unittype == 'B'

tabulate buildingtype
generate buildingtype_gr = substr(buildingtype,1,2)
keep if inlist(buildingtype_gr,'11','12','13','14')

textblock
Power consumption vs. building type
endblock
tabulate buildingtype, summarize(usablearea) mean freq
tabulate buildingtype, summarize(powerconsumption1) mean freq
barchart(count) buildingtype
barchart(mean) usablearea, over(buildingtype)
barchart(mean) powerconsumption1, over(buildingtype)
barchart(mean) consumption_per_m2, over(buildingtype)

textblock
Power consumption vs. number of rooms and people
endblock
tabulate num_rooms, summarize(powerconsumption1)
tabulate num_people, summarize(powerconsumption1)
barchart(mean) powerconsumption1, over(num_rooms)
barchart(mean) consumption_per_m2, over(num_rooms)
barchart(mean) powerconsumption1, over(num_people)
barchart(mean) consumption_per_m2, over(num_people)

textblock
Power consumption vs. year of construction
endblock
recode constructionyear (min/1939 = 1 'Before world war 2')(1940/1959 = 2 '40s and 50s')(1960/1969 = 3 '60s')(1970/1979 = 4 '70s')(1980/1989 = 5 '80s')(1990/1999 = 6 '90s')(2000/2009 = 7 '00s')(2010/2019 = 8 '10s')(2020/max = 9 '20s')
tabulate constructionyear
barchart(count) constructionyear
barchart(mean) powerconsumption1, over(constructionyear)
barchart(mean) consumption_per_m2, over(constructionyear)

textblock
Power consumption vs. dwelling size and income
endblock
hexbin powerconsumption1 usablearea, gridsize(25)
hexbin power

textblock
Electricity consumption vs. dwelling size and income
endblock
hexbin electricityconsumption1 usablearea, gridsize(25)
hexbin electricityconsumption1 householdincome, gridsize(25)

recode usablearea (min/49 = 1 'Under 50')(50/99 = 2 '50-99')(100/149 = 3 '100-149')(150/199 = 4 '150-199')(200/249 = 5 '200-249')(250/299 = 6 '250-299')(300/max = 7 '300 ->')
barchart(mean) electricityconsumption1, over(usablearea)
barchart(mean) consumption_per_m2, over(usablearea)